﻿using FlyHorse.LIMS.IBLL;
using FlyHorse.LIMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FlyHorse.LIMS.BLL
{
    public partial class ReportMixBll : BaseBll<ReportMix>, IReportMixBll
    {
        public List<ReportMixResult> GetEmptResultList(string goodsId)
        {
            List<ReportMixResult> resList = new List<ReportMixResult>();
            var standardList = this.CurrentDBSession.StandardSemiDal.LoadEntitiesAsNoTracking(m => m.GoodsID == goodsId && m.SamplingPlaceID == "2").ToList();
            foreach (var standard in standardList)
            {
                ReportMixResult reportMixResult = new ReportMixResult();
                reportMixResult.TestItemID = standard.TestItemID;
                reportMixResult.Basis = standard.TestItem.Basis;
                reportMixResult.ChineseName = standard.TestItem.ChineseName;
                reportMixResult.Conclusion = "";
                reportMixResult.FormOrder = standard.FormOrder;
                reportMixResult.ReportMixResultID = Guid.NewGuid().ToString();
                reportMixResult.MaxValue = standard.MaxValue;
                reportMixResult.MinValue = standard.MinValue;
                reportMixResult.TestValue = null;
                reportMixResult.Unit = standard.TestItem.Unit;
                resList.Add(reportMixResult);
            }
            resList = resList.OrderBy(m=>m.FormOrder).ToList();
            return resList;
        }

        public bool DeleteMixReport(int id)
        {
            ReportMix report = this.CurrentDBSession.Db.Set<ReportMix>().Find(id);
            if (report!=null)
            {
                this.CurrentDBSession.Db.Set<ReportMix>().Remove(report);
                int count = this.CurrentDBSession.Db.SaveChanges();
                if (count>0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }


      
    }
}
